home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / Librarys / MMULib / C_Sources / MuRemapTest.c < prev    next >
C/C++ Source or Header  |  1999-05-26  |  22KB  |  603 lines

  1. /*************************************************
  2.  ** MuRemapTest                                 **
  3.  ** experimental MMU memory remapper            **
  4.  **                                             **
  5.  ** This program checks for correctness of the  **
  6.  ** device drivers and correct MMU support      **
  7.  **                                             **
  8.  ** Note that device drivers have to call       **
  9.  ** CachePreDMA() and CachePostDMA() to be      **
  10.  ** notified about the TRUE physical addresses  **
  11.  ** some devices might fail here                **
  12.  **                                             **
  13.  ** Version 40.0        26 May 1999             **
  14.  ** © THOR Thomas Richter                       **
  15.  *************************************************/
  16.  
  17. /// Includes
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <exec/ports.h>
  21. #include <exec/execbase.h>
  22. #include <dos/dos.h>
  23.  
  24. /* MMU specific includes */
  25. #include <mmu/mmubase.h>
  26. #include <mmu/context.h>
  27. #include <mmu/mmutags.h>
  28.  
  29. #include <workbench/startup.h>
  30.  
  31. #include <proto/exec.h>
  32. #include <proto/mmu.h>
  33. #include <proto/dos.h>
  34. #include <proto/icon.h>
  35. #include <string.h>
  36. ///
  37. /// Defines
  38. #define STRINGDATE "5.3.99"
  39. #define STRINGVERSION "40.0"
  40.  
  41. /* Defines for the shell template */
  42. #define TEMPLATE "TEMPFILE/A"
  43.  
  44. #define OPT_DEVICE 0
  45. #define OPT_WINDOW 1
  46. #define OPT_COUNT 2
  47. ///
  48. /// Statics
  49.  
  50. /* just the library bases */
  51. struct MMUBase *MMUBase;
  52. struct DosLibrary *DOSBase;
  53. struct ExecBase *SysBase;
  54. struct Library *IconBase;
  55. ///
  56. /// Protos
  57.  
  58. /* prototyping */
  59. int __asm __saveds main(void);
  60. struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp);
  61. int CheckRemapping(char *filename);
  62. BOOL SetRemap(struct MMUContext *ctx,struct MemHeader *physical,struct MemHeader *logical,ULONG size);
  63. void FileTest(char *filename,void *physical,void *logical,ULONG size);
  64. BOOL ForceRebuild(struct MMUContext *ctx);
  65. struct MemHeader *MemHeaderOf(void *mem);
  66. ///
  67.  
  68. char version[]="$VER: MuRemapTest " STRINGVERSION " (" STRINGDATE ") © THOR";
  69.  
  70. /// main
  71. int __asm __saveds main(void)
  72. {
  73. LONG args[OPT_COUNT];
  74. struct RDArgs *rd,*myrd;
  75. struct Process *proc;
  76. int rc=20;
  77. LONG err;
  78. struct WBStartup *msg;
  79. BPTR oldout;
  80. struct MsgPort *oldconsole;
  81.  
  82.  
  83.         /* This program is compiled without startup code, hence we have
  84.            to setup ourselfs */
  85.  
  86.         SysBase=*((struct ExecBase **)(4L));
  87.  
  88.         /* clear the arguments */
  89.         memset(args,0,sizeof(LONG)*OPT_COUNT);
  90.  
  91.         /* Wait for the workbench startup, if any */
  92.         proc=(struct Process *)FindTask(NULL);
  93.  
  94.         if (!(proc->pr_CLI)) {
  95.                 WaitPort(&(proc->pr_MsgPort));
  96.                 msg=(struct WBStartup *)GetMsg(&(proc->pr_MsgPort));
  97.         } else  msg=NULL;
  98.  
  99.  
  100.         /* Open the libraries we need */
  101.  
  102.         if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
  103.                 if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",0L)) {
  104.  
  105.                         err=ERROR_REQUIRED_ARG_MISSING;
  106.  
  107.                         myrd=NULL;      /* reset the temporary ReadArgs */
  108.                         oldout=NULL;
  109.                         oldconsole=NULL;
  110.  
  111.                         /* Check whether we're run from workbench or
  112.                            shell. On a WBRun, we parse the tool types
  113.                            and setup our own output stream, keeping
  114.                            the old one - which will be NULL anyways... */
  115.  
  116.                         if (msg) {
  117.                                 oldout=SelectOutput(NULL);
  118.                                 oldconsole=SetConsoleTask(NULL);
  119.                                 rd=ReadTTArgs(msg,args,&myrd);
  120.                         } else  rd=ReadArgs(TEMPLATE,args,NULL);
  121.  
  122.                         if (rd) {
  123.  
  124.                                 /* Check for a working MMU. The mmu library
  125.                                    will open anyways, even without one. */
  126.  
  127.                                 if (!GetMMUType()) {
  128.                                         Printf("MuRemapTest requires a working MMU.\n");
  129.                                         err=10;
  130.                                 } else {
  131.                                         /* Argument parser worked, call main routine */
  132.                                         err=CheckRemapping((char *)(args[OPT_DEVICE]));
  133.                                 }
  134.  
  135.                                 /* Shut down */
  136.  
  137.                                 FreeArgs(rd);
  138.                                 if (myrd) FreeDosObject(DOS_RDARGS,myrd);
  139.                                 if (msg)  Close(SelectOutput(NULL));
  140.                         } else  err=IoErr();
  141.  
  142.                         if (msg) {
  143.                                 SelectOutput(oldout);
  144.                                 SetConsoleTask(oldconsole);
  145.                         }
  146.  
  147.                         /* we're done. Check for the result code. If
  148.                            it is below 64, it is passed over as primary
  149.                            result code. */
  150.  
  151.                         if (err<64) {
  152.                                 rc=err;
  153.                                 err=0;
  154.                         } else {
  155.                                 if (!msg) PrintFault(err,"MuRemapTest failed");
  156.                                 rc=10;
  157.                         }
  158.                         SetIoErr(err);
  159.  
  160.                         CloseLibrary((struct Library *)MMUBase);
  161.                 } else PrintFault(ERROR_OBJECT_NOT_FOUND,"MuRemapTest requires the mmu.library");
  162.                 CloseLibrary((struct Library *)DOSBase);
  163.         }
  164.  
  165.         return rc;
  166. }
  167. ///
  168. /// ReadTTArgs
  169. struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp)
  170. {
  171. struct WBArg *wbarg;
  172. struct DiskObject *dop;
  173. char **tt;                      /* ToolTypes array */
  174. char *wbstr;                    /* Our self-made workbench argument string */
  175. char *here;
  176. BPTR oldlock;
  177. ULONG len;
  178. struct RDArgs *rd=NULL,*myrd=NULL;
  179. LONG err=0;
  180. BPTR newout;
  181.  
  182.  
  183.         /* Parse the tool type string for arguments...
  184.            this is mainly Mike's code. */
  185.  
  186.         if (IconBase=OpenLibrary("icon.library",37L)) {
  187.                 if (wbarg=msg->sm_ArgList) {
  188.                         /* use a project icon if there is one... */
  189.                         if (msg->sm_NumArgs > 1) wbarg++;
  190.  
  191.                         /* go into the directory */
  192.                         oldlock=CurrentDir(wbarg->wa_Lock);
  193.  
  194.                         if (dop=GetDiskObject(wbarg->wa_Name)) {
  195.                                 if (tt=dop->do_ToolTypes) {
  196.                                         /* Read a special tool type for the output window */
  197.  
  198.                                         /* Calc the size of the argument string */
  199.  
  200.                                         len = 3;        /* reserve space for SPC,LF,NUL */
  201.                                         while (*tt) {
  202.                                                 len += strlen(*tt)+1;   /* string, plus space */
  203.                                                 tt++;
  204.                                         }
  205.  
  206.                                         if (wbstr=AllocVec(len,MEMF_PUBLIC)) {
  207.                                                 /* Now copy the arguments into this string, one by one
  208.                                                    and check whether the argument string is still valid. */
  209.  
  210.                                                 tt=dop->do_ToolTypes;
  211.                                                 here=wbstr;
  212.                                                 do{
  213.                                                         *here='\0';                     /* terminate string */
  214.                                                         /* Check whether this tool type is
  215.                                                            commented out. Just ignore it in this case */
  216.                                                         if (*tt) {
  217.                                                                 if (**tt=='(' || **tt==';')
  218.                                                                         continue;
  219.  
  220.                                                                 strcpy(here,*tt);      /* Add TT string */
  221.